<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 将 singleTon 改成 Person，完全没问题，和里面的不冲突
    const Person = (function () {
      // 真实的构造类 
      function Person(name, age, gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
      }
      Person.prototype.say = function say() {
        console.log('say hello')
      }
      let instance = null;
      return function (...args) {
        if (!instance) instance = new Person(...args);
        return instance;
      }
    })();

    let p1 = new Person('Henry', 18, 'male')
    let p2 = new Person()

    console.log(p1, p2)
    console.log(p1 === p2) //=> true
  </script>
</body>

</html>